package com.onenine.chat.util;

import android.annotation.SuppressLint;
import android.content.Context;

import com.onenine.app.R;
import com.onenine.common.util.ApUtils;

import io.rong.calllib.RongCallCommon;
import io.rong.calllib.message.CallSTerminateMessage;

/**
 * 创建时间：2018/6/27 0027 14:35
 * 创建人：fly
 * 功能描述：
 */
public class RcMessageConverter {

    public static String convertCallDisconnectedReason(RongCallCommon.CallDisconnectedReason reason) {
        Context context = ApUtils.getApp();
        String text = "";
        switch (reason) {
            case CANCEL:
                text = context.getString(R.string.rc_voip_mo_cancel);
                break;
            case REJECT:
                text = context.getString(R.string.rc_voip_mo_reject);
                break;
            case NO_RESPONSE:
            case BUSY_LINE:
                text = context.getString(R.string.rc_voip_mo_no_response);
                break;
            case REMOTE_BUSY_LINE:
                text = context.getString(R.string.rc_voip_mt_busy);
                break;
            case REMOTE_CANCEL:
                text = context.getString(R.string.rc_voip_mt_cancel);
                break;
            case REMOTE_REJECT:
                text = context.getString(R.string.rc_voip_mt_reject);
                break;
            case REMOTE_NO_RESPONSE:
                text = context.getString(R.string.rc_voip_mt_no_response);
                break;
            case REMOTE_HANGUP:
            case HANGUP:
            case NETWORK_ERROR:
            case INIT_VIDEO_ERROR:
                text = context.getString(R.string.rc_voip_call_terminalted);
                break;
            case OTHER_DEVICE_HAD_ACCEPTED:
                text = context.getString(R.string.rc_voip_call_other);
                break;
        }
        return text;
    }

    /**
     * 转换对方下线的行为原因
     *
     * @param reason
     * @return
     */
    public static String convertRemoteCallDisconnectedReason(RongCallCommon.CallDisconnectedReason reason) {
        Context context = ApUtils.getApp();
        String text = "";
        switch (reason) {
            case REMOTE_BUSY_LINE:
                text = context.getString(R.string.rc_voip_mt_busy);
                break;
            case REMOTE_CANCEL:
                text = context.getString(R.string.rc_voip_mt_cancel);
                break;
            case REMOTE_REJECT:
                text = context.getString(R.string.rc_voip_mt_reject);
                break;
            case NO_RESPONSE:
                text = context.getString(R.string.rc_voip_mt_no_response);
                break;
            case NETWORK_ERROR:
            case HANGUP:
            case REMOTE_HANGUP:
                text = context.getString(R.string.rc_voip_call_terminalted);
                break;
        }
        return text;
    }

    @SuppressLint("StringFormatInvalid")
    public static String convertCallTerminalDesc(CallSTerminateMessage callSTerminateMessage) {
        Context context = ApUtils.getApp();
        String text = "";
        switch (callSTerminateMessage.getReason()) {
            case CANCEL:
                text = context.getString(R.string.rc_voip_mo_cancel);
                break;
            case REJECT:
                text = context.getString(R.string.rc_voip_mo_reject);
                break;
            case NO_RESPONSE:
            case BUSY_LINE:
                text = context.getString(R.string.rc_voip_mo_no_response);
                break;
            case REMOTE_BUSY_LINE:
                text = context.getString(R.string.rc_voip_mt_busy);
                break;
            case REMOTE_CANCEL:
                text = context.getString(R.string.rc_voip_mt_cancel);
                break;
            case REMOTE_REJECT:
                text = context.getString(R.string.rc_voip_mt_reject);
                break;
            case REMOTE_NO_RESPONSE:
                text = context.getString(R.string.rc_voip_mt_no_response);
                break;
            case REMOTE_HANGUP:
            case HANGUP:
                text = context.getString(R.string.rc_voip_call_communication_duration, callSTerminateMessage.getExtra());
                break;
            case NETWORK_ERROR:
            case INIT_VIDEO_ERROR:
                text = context.getString(R.string.rc_voip_call_terminalted);
                break;
            case OTHER_DEVICE_HAD_ACCEPTED:
                text = context.getString(R.string.rc_voip_call_other);
                break;
        }
        return text;
    }
}
